frappe.ui.form.on("Work Order", {
	zelin_split_qty: function(frm) {
        const dialog = frappe.prompt({
                fieldname: 'qty', 
                fieldtype: 'Float',
                reqd: 1,
                label: __('Split Qty')      
            }, function(data) {
                frappe.call({
                    method: "zelin_pp.api.split_work_order",
                    freeze: true,
                    args: {
                        work_order_name: frm.doc.name,
                        qty: dialog.get_values().qty,
                    }
                }).then((r)=>{
                    if (r.message !== frm.docname){
                        frappe.model.with_doc("Work Order", r.message
                            ).then(
                                ()=>{
                                    frappe.set_route("Form", "Work Order", r.message)
                            })
                    }else {
                        frm.reload_doc()
                    }
                })
            })
    }        
})